package com.affectu.forum;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.validator.Length;
import org.jboss.seam.annotations.Name;

import com.affectu.common.base.EntityBase;
import com.affectu.user.User;

/**
 * Oct 7, 2008
 * 
 * @author daniel nathan
 */
@Entity
@Name("article")
public class Article extends EntityBase {

	private static final long serialVersionUID = 4002896564850096475L;

	// @Column(columnDefinition = "MEDIUMTEXT")
	@Length(max = 10240)
	private String content;

	@ManyToOne(cascade = CascadeType.REFRESH)
	@JoinColumn(name = "plateId", referencedColumnName = "id")
	private Plate plate;

	@ManyToOne(cascade = CascadeType.REFRESH)
	@JoinColumn(name = "senderId", referencedColumnName = "id")
	private User sender;

	@Temporal(value = TemporalType.TIMESTAMP)
	private Date sendDate;

	@ManyToOne
	@JoinColumn(name = "parentId")
	private Article parent;

	@OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)
	private List<Article> children;

	private int hitCount;

	private Status status;

	public enum Status {
		NEW, READED, TRASH
	};

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public User getSender() {
		return sender;
	}

	public void setSender(User sender) {
		this.sender = sender;
	}

	public Date getSendDate() {
		return sendDate;
	}

	public void setSendDate(Date sendDate) {
		this.sendDate = sendDate;
	}

	public Article getParent() {
		return parent;
	}

	public void setParent(Article parent) {
		this.parent = parent;
	}

	public List<Article> getChildren() {
		return children;
	}

	public void setChildren(List<Article> children) {
		this.children = children;
	}

	public int getHitCount() {
		return hitCount;
	}

	public void setHitCount(int hitCount) {
		this.hitCount = hitCount;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public Plate getPlate() {
		return plate;
	}

	public void setPlate(Plate plate) {
		this.plate = plate;
	}
}
